package com.erpanderp.wam.util.model.service;

import org.hibernate.FlushMode;
import org.hibernate.Session;

import com.erpanderp.wam.util.HibernateUtil;
import com.erpanderp.wam.util.model.entity.WAMEmail;

public class WAMEmailDAO {

	public boolean recordWAMEmail(WAMEmail wamEmail) {
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.getTransaction().begin();
			System.out.println("FLUSH MODE: " + session.getFlushMode());
			session.setFlushMode(FlushMode.COMMIT);
			session.save(wamEmail);
			session.getTransaction().commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}
	
	public boolean updateWAMEmail(WAMEmail wamEmail) {
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.getTransaction().begin();
			System.out.println("FLUSH MODE: " + session.getFlushMode());
			session.setFlushMode(FlushMode.COMMIT);
			session.saveOrUpdate(wamEmail);
			session.getTransaction().commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}
}
